package com.bulletelc.apollopre.module.deal.pay;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bulletelc.apollopre.R;
import com.bulletelc.apollopre.entity.PayTypeBean;
import com.bulletelc.apollopre.manager.imageload.ImageLoaderManager;

import java.util.List;

/**
 * author: lhl
 * date  : 2018/01/21
 * desc  : TODO
 */

public class PayTypeAdapter extends BaseAdapter {

    private Context context;
    private List<PayTypeBean> payTypeBeans;
    private LayoutInflater inflater;

    public PayTypeAdapter(Context context, List<PayTypeBean> payTypeBeans) {
        this.context = context;
        this.payTypeBeans = payTypeBeans;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return payTypeBeans.size();
    }

    @Override
    public Object getItem(int position) {
        return payTypeBeans.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        PayTypeBean payTypeBean=payTypeBeans.get(position);
        ViewHolder holder;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = inflater.inflate(R.layout.pay_type_item, parent, false);
            holder.ivIcon = convertView.findViewById(R.id.ivPayTypeIcon);
            holder.tvPayType = convertView.findViewById(R.id.tvPayType);
            holder.ivSelected = convertView.findViewById(R.id.ivSelected);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.tvPayType.setText(payTypeBean.getLabel());
        if (payTypeBean.getIs_default() == 1) {
            holder.ivSelected.setVisibility(View.VISIBLE);
        } else {
            holder.ivSelected.setVisibility(View.GONE);
        }

        ImageLoaderManager.getInstance().loadImage(ImageLoaderManager.getDefaultOptions(holder.ivIcon, payTypeBean.getOriginalUrl()));
        return convertView;
    }

    class ViewHolder{
        ImageView ivIcon;
        TextView tvPayType;
        ImageView ivSelected;
    }
}
